﻿using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.Linq;

namespace BgTransAPI.ControllerHelpers
{
    public class HtmlDataExtractor
    {
        private HtmlDocument doc;

        public HtmlDataExtractor(string html)
        {
            this.doc = new HtmlDocument();
            this.doc.LoadHtml(html);
        }

        public ICollection<string> GetShedules()
        {
                ICollection<string> times = new List<string>();
                var divNodes = this.doc.DocumentNode.SelectNodes("//table[@id='ctl00_ContentPlaceHolder1_gvTimes']/tr[@align='left']/td[3]/div");
                if (divNodes != null)
                {                   
                    foreach (var div in divNodes)
                    {
                                             
                      string text = div.InnerText.Trim();
                      times.Add(div.InnerText.Substring(0, text.IndexOf(' ')));
                                              
                    }

                    return times;
                }

            throw new ArgumentNullException("Failed to parse HTML responce!");

        }
    }
}